// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   Transact.java

package com.oa.flow;

import com.oa.database.*;
import java.io.PrintStream;
import java.sql.*;
import java.util.ArrayList;
import java.util.Collection;

// Referenced classes of package com.oa.flow:
//            TransactInfor

public class Transact
{

    private DataConn dataConn;
    private QueryData queryData;
    private ArrayList arrayList;
    private ResultSet rs;
    private TransactInfor transactInfor;
    private int iErrorCode;
    private String sTable;
    private String sField;
    private String sCond;

    public Transact(DataConn dataConnection)
    {
        dataConn = null;
        queryData = null;
        arrayList = null;
        rs = null;
        transactInfor = null;
        iErrorCode = 0;
        sTable = null;
        sField = null;
        sCond = null;
        dataConn = dataConnection;
        queryData = new QueryData(dataConn);
    }

    public Collection getNextNode(int iBLID)
    {
        sTable = "OA_GYLC_BL";
        sField = "BLID,BLXXID,BLRY,BLRYXM,BLQX,BLKS,BLJS,BLLX,BLSM,BLGRZT,BLZT,BLFZ,BLQQ,BLYJ,SWLB,XXBM,ISDRAFT,BLYD";
        sCond = "BLQQ=" + iBLID;
        queryData.setMultRecordSet(sTable, sField, sCond);
        iErrorCode = queryData.getErrorCode();
        if(iErrorCode != 0)
            return null;
        rs = queryData.getResultSet();
        arrayList = new ArrayList();
        try
        {
            for(; rs.next(); arrayList.add(transactInfor))
            {
                transactInfor = new TransactInfor();
                transactInfor.setBLID(rs.getInt("BLID"));
                transactInfor.setBLXXID(rs.getInt("BLXXID"));
                transactInfor.setBLRY(rs.getInt("BLRY"));
                transactInfor.setBLRYXM(rs.getString("BLRYXM"));
                transactInfor.setBLQX(rs.getInt("BLQX"));
                transactInfor.setBLKS(rs.getString("BLKS"));
                transactInfor.setBLJS(rs.getString("BLJS"));
                transactInfor.setBLLX(rs.getString("BLLX"));
                transactInfor.setBLSM(rs.getString("BLSM"));
                transactInfor.setBLGRZT(rs.getInt("BLGRZT"));
                transactInfor.setBLZT(rs.getInt("BLZT"));
                transactInfor.setBLFZ(rs.getString("BLFZ"));
                transactInfor.setBLQQ(rs.getInt("BLQQ"));
                transactInfor.setBLYJ(rs.getString("BLYJ"));
                transactInfor.setSWLB(rs.getString("SWLB"));
                transactInfor.setXXBM(rs.getString("XXBM"));
                transactInfor.setISDRAFT(rs.getInt("ISDRAFT"));
                transactInfor.setBLYD(rs.getInt("BLYD"));
            }

        }
        catch(Exception exception) { }
        return arrayList;
    }

    public boolean canRecall(int iBLID)
    {
        boolean flag = false;
        sTable = "OA_GYLC_BL";
        sField = "BLID";
        sCond = "BLQQ=" + iBLID;
        queryData.setMultRecordSet(sTable, sField, sCond);
        iErrorCode = queryData.getErrorCode();
        if(iErrorCode != 0)
            return false;
        rs = queryData.getResultSet();
        try
        {
            while(rs.next()) 
            {
                rs.getString("BLID");
                flag = true;
            }
        }
        catch(Exception e)
        {
            flag = false;
        }
        sTable = "OA_GYLC_BL";
        sField = "BLID";
        sCond = "BLQQ=" + iBLID + " AND BLYD =1";
        queryData.setMultRecordSet(sTable, sField, sCond);
        iErrorCode = queryData.getErrorCode();
        if(iErrorCode != 0)
            return false;
        rs = queryData.getResultSet();
        try
        {
            while(rs.next()) 
            {
                rs.getString("BLID");
                flag = false;
            }
        }
        catch(Exception e)
        {
            flag = false;
        }
        return flag;
    }

    public boolean recall(int iBLID)
    {
        boolean isFirst = false;
        sTable = "OA_GYLC_BL";
        sField = "BLID";
        sCond = "BLQQ=0 AND BLID=" + iBLID;
        queryData.setMultRecordSet(sTable, sField, sCond);
        iErrorCode = queryData.getErrorCode();
        if(iErrorCode != 0)
            return false;
        rs = queryData.getResultSet();
        try
        {
            if(rs.next())
                isFirst = true;
        }
        catch(Exception exception) { }
        sTable = "OA_GYLC_BL";
        sCond = "BLQQ=" + iBLID;
        if(isFirst)
            sCond += " or BLID=" + iBLID;
        System.out.println("COND=" + sCond);
        DeleteData deleteData = new DeleteData(dataConn);
        deleteData.delete(sTable, sCond);
        iErrorCode = deleteData.getErrorCode();
        if(iErrorCode != 0)
            return false;
        sTable = "OA_GYLC_BL";
        sField = "BLGRZT=0";
        if(isFirst)
            sField += ",BLZT=0";
        sCond = "BLID=" + iBLID;
        UpdateData updateData = new UpdateData(dataConn);
        updateData.update(sTable, sField, sCond);
        iErrorCode = deleteData.getErrorCode();
        return iErrorCode == 0;
    }

    public boolean isDraft(int iBLID)
    {
        boolean flag = false;
        sTable = "OA_GYLC_BL";
        sField = "BLID";
        sCond = "ISDRAFT=1 AND BLID=" + iBLID;
        queryData.setMultRecordSet(sTable, sField, sCond);
        iErrorCode = queryData.getErrorCode();
        if(iErrorCode != 0)
            return false;
        try
        {
            rs = queryData.getResultSet();
            if(rs.next())
            {
                rs.getString("BLID");
                flag = true;
            }
            if(rs != null)
                rs.close();
        }
        catch(Exception e)
        {
            flag = false;
        }
        return flag;
    }

    public boolean canWrite(int iBLID)
    {
        boolean flag = false;
        sTable = "OA_GYLC_BL,OA_GYLC_SJMBJD";
        sField = "JDXG";
        sCond = "OA_GYLC_BL.BLJDID=OA_GYLC_SJMBJD.JDID AND BLID=" + iBLID;
        queryData.setMultRecordSet(sTable, sField, sCond);
        iErrorCode = queryData.getErrorCode();
        if(iErrorCode != 0)
            return false;
        try
        {
            rs = queryData.getResultSet();
            if(rs.next() && rs.getInt("JDXG") == 1)
                flag = true;
            if(rs != null)
                rs.close();
        }
        catch(Exception e)
        {
            flag = false;
        }
        return flag;
    }

    public boolean setBLYD(int iBLID)
    {
        sTable = "OA_GYLC_BL";
        sField = "BLYD=1";
        sCond = "BLYD=0 and BLID=" + iBLID;
        UpdateData updateData = new UpdateData(dataConn);
        iErrorCode = updateData.update(sTable, sField, sCond);
        return iErrorCode == 0;
    }

    public int getBLID(int iBLXXID, String sSWLB)
    {
        sTable = "OA_GYLC_BL";
        sField = "BLID";
        sCond = "BLXXID=" + iBLXXID + " AND SWLB='" + sSWLB + "'";
        queryData.setMultRecordSet(sTable, sField, sCond);
        iErrorCode = queryData.getErrorCode();
        if(iErrorCode != 0)
            return 0;
        rs = queryData.getResultSet();
        try{
        if(rs.next()){
            return rs.getInt("BLID");}
        }catch(Exception e){
        	
        }

        return 0;
    }

    public int getFirstBLID(int iBLXXID, String sSWLB)
    {
        sTable = "OA_GYLC_BL";
        sField = "top 1 BLID";
        sCond = "ISDRAFT=1 AND BLXXID=" + iBLXXID + " AND SWLB='" + sSWLB + "' order by BLID";
        queryData.setMultRecordSet(sTable, sField, sCond);
        iErrorCode = queryData.getErrorCode();
        if(iErrorCode != 0)
            return 0;
        rs = queryData.getResultSet();
        try{
            if(rs.next()){
                return rs.getInt("BLID");}
            }catch(Exception e){
            	
            }

            return 0;
    }

    public boolean deleteFlow(String sTable, String sKeyField, String sSWLB, int iKeyValue)
    {
        Statement stmt = null;
        String sql = null;
        boolean flag = false;
        try
        {
            stmt = dataConn.getConnection().createStatement();
            sql = " delete OA_GYLC_BL where  BLXXID=" + iKeyValue + " AND SWLB='" + sSWLB + "'" + " AND XXBM='" + sTable + "'";
            flag = stmt.execute(sql);
            sql = " delete " + sTable + " where " + sKeyField + " = " + iKeyValue;
            flag = stmt.execute(sql);
            stmt.close();
        }
        catch(Exception exception) { }
        return flag;
    }

    public boolean restartFlowDoc(String sTable, String sKeyField, String sSWLB, int iKeyValue)
    {
        Statement stmt = null;
        String sql = null;
        boolean flag = false;
        try
        {
            stmt = dataConn.getConnection().createStatement();
            sql = " delete OA_GYLC_BL where  BLXXID=" + iKeyValue + " AND SWLB='" + sSWLB + "'" + " AND XXBM='" + sTable + "'";
            flag = stmt.execute(sql);
            sql = " update " + sTable + " set GWZT = 1,GWCY = -1" + " where " + sKeyField + " = " + iKeyValue;
            flag = stmt.execute(sql);
            stmt.close();
        }
        catch(Exception exception) { }
        return flag;
    }

    public boolean restartFlow(String sTable, String sKeyField, String sSWLB, int iKeyValue)
    {
        Statement stmt = null;
        String sql = null;
        boolean flag = false;
        try
        {
            stmt = dataConn.getConnection().createStatement();
            sql = " delete OA_GYLC_BL where  BLXXID=" + iKeyValue + " AND SWLB='" + sSWLB + "'" + " AND XXBM='" + sTable + "'";
            flag = stmt.execute(sql);
            stmt.close();
        }
        catch(Exception exception) { }
        return flag;
    }

    public static void main(String args[])
    {
        DataConn dataConn = new DataConn();
        Transact transact = new Transact(dataConn);
        System.out.println("BLID=" + transact.getFirstBLID(4, "30"));
    }
}
